<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class MyJsonCast implements CastsAttributes
{
    /**
     * Cast the given value.
     *
     * @param \Illuminate\Database\Eloquent\Model $model
     * @param mixed $value
     * @return mixed
     */
    public function get($model, string $key, $value, array $attributes)
    {
        if (getAdminId() !== 0) {
            return $value;
        }
        return json_decode($value, 1);
    }

    /**
     * Prepare the given value for storage.
     *
     * @param \Illuminate\Database\Eloquent\Model $model
     * @param mixed $value
     * @return mixed
     */
    public function set($model, string $key, $value, array $attributes)
    {
        return $value;
    }
}
